﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Collections.Generic;
using EZCRS.HCMS.Bll;
using EZCRS.HCMS.Web;
using EZCRS.HCMS.Bll.baseinfo;
using EZCRS.HCMS.Entity;

namespace EZCRS.HCMS.Web.manage.hotel
{
    public partial class local : ManageBase
    {
        BllHCRS_HotelLocal _local = new BllHCRS_HotelLocal();
        protected void Page_Load(object sender, EventArgs e)
        {
            CheckModule(54);
            if (base.BasHotelId == 0)
            {
                Response.Write(CFun.AlertMeg(Resources.Site.MustHotel, "back", ""));
                return;
            }
            
            if (!Page.IsPostBack)
                getdata();
        }

        protected void btnsave_Click(object sender, EventArgs e)
        {
            _local.savedescription(txtLocation.Text, txtTransportation.Text,txtLongitude.Text,txtLatitude.Text, base.BasPropertyId,Convert.ToInt32(hid5.Value));
            
            #region
            if (txtairportname1.Value.Trim() != "")
            {
                HCRS_Airport _airport = new HCRS_Airport();
                _airport.Id = Convert.ToInt32(hid1.Value);
                _airport.Property_id = base.BasPropertyId;
                _airport.AirportUnits = ddlUnit1.SelectedValue;
                _airport.AirportTrans = txttran1.Value;
                _airport.Airports = txtairportname1.Value;
                _airport.AirportDistance = Convert.ToInt32(txtDis1.Value);
                _airport.AirportDirection = ddldir1.SelectedValue;
                _local.modifyairport(_airport); 
            }
            if (txtairportname2.Value.Trim() != "")
            {
                HCRS_Airport _airport = new HCRS_Airport();
                _airport.Id = Convert.ToInt32(hid2.Value);
                _airport.Property_id = base.BasPropertyId;
                _airport.AirportUnits = ddlUnit2.SelectedValue;
                _airport.AirportTrans = txttran2.Value;
                _airport.Airports = txtairportname2.Value;
                _airport.AirportDistance = Convert.ToInt32(txtDis2.Value);
                _airport.AirportDirection = ddldir2.SelectedValue;
                _local.modifyairport(_airport);
            }
            #endregion
            
            #region
            if (txttrainname1.Value.Trim() != "")
            {
                HCRS_Train _train = new HCRS_Train();
                _train.Id = Convert.ToInt32(hid3.Value);
                _train.Property_id = base.BasPropertyId;
                _train.TrainDirection = ddldir3.SelectedValue;
                _train.TrainDistance = Convert.ToInt32(txttraindis1.Value);
                _train.TrainName = txttrainname1.Value;
                _train.TrainTrans = txttran3.Value;
                _train.TrainUnits = ddlUnit3.SelectedValue;
                _local.modifytrain(_train);
            }
            if (txttrainname2.Value.Trim() != "")
            {
                HCRS_Train _train = new HCRS_Train();
                _train.Id = Convert.ToInt32(hid4.Value);
                _train.Property_id = base.BasPropertyId;
                _train.TrainDirection = ddldir4.SelectedValue;
                _train.TrainDistance = Convert.ToInt32(txttraindis2.Value);
                _train.TrainName = txttrainname2.Value;
                _train.TrainTrans = txttran4.Value;
                _train.TrainUnits = ddlUnit4.SelectedValue;
                _local.modifytrain(_train);
            }
            #endregion

            Page.ClientScript.RegisterClientScriptBlock(typeof(String), "scuress", CFun.AlertMeg(Resources.Site.SystemModifySuccess, "", "local.aspx"));
        }

        private void getdata()
        {
            #region
            CFun.SetListControl(ddldir1, EZCRS.HCMS.Bll.baseinfo.HotelBaseInfo.AirPortLocal(), "");
            CFun.SetListControl(ddldir2, EZCRS.HCMS.Bll.baseinfo.HotelBaseInfo.AirPortLocal(), "");
            CFun.SetListControl(ddldir3, EZCRS.HCMS.Bll.baseinfo.HotelBaseInfo.AirPortLocal(), "");
            CFun.SetListControl(ddldir4, EZCRS.HCMS.Bll.baseinfo.HotelBaseInfo.AirPortLocal(), "");

            CFun.SetListControl(ddlUnit1, EZCRS.HCMS.Bll.baseinfo.HotelBaseInfo.TrafficUnit() , "");
            CFun.SetListControl(ddlUnit2, EZCRS.HCMS.Bll.baseinfo.HotelBaseInfo.TrafficUnit(), "");
            CFun.SetListControl(ddlUnit3, EZCRS.HCMS.Bll.baseinfo.HotelBaseInfo.TrafficUnit(), "");
            CFun.SetListControl(ddlUnit4, EZCRS.HCMS.Bll.baseinfo.HotelBaseInfo.TrafficUnit(), "");

            List<HCRS_Airport> _airportlist = _local.getallairport(base.BasPropertyId);
            List<HCRS_Train> _trainlist = _local.getalltrain(base.BasPropertyId);
            HCRS_Description _description = _local.getdescription(base.BasPropertyId);
            HCRS_Hotel _hotel = _local.gethotel(base.BasHotelId);
            if (_description != null)
            {
                txtLocation.Text = _description.Location;
                txtTransportation.Text = _description.Transportation;
                hid5.Value = _description.Property_id.ToString();
            }
           
            if (_hotel != null)
            {
                txtLongitude.Text = _hotel.localLongitude;
                txtLatitude.Text = _hotel.localLatitude;
            }
            else
                return;
            if (_airportlist.Count > 0)
            {
                ddldir1.SelectedValue = _airportlist[0].AirportDirection;
                ddlUnit1.SelectedValue = _airportlist[0].AirportUnits;
                txtairportname1.Value = _airportlist[0].Airports;
                txtairportnamecomm1.Value = new Bll.baseinfo.BllAirCode().getcodename(_airportlist[0].Airports);
                txtDis1.Value = _airportlist[0].AirportDistance.ToString();
                txttran1.Value = _airportlist[0].AirportTrans;
                hid1.Value = _airportlist[0].Id.ToString();
            }
            if (_airportlist.Count > 1)
            {
                ddldir2.SelectedValue = _airportlist[1].AirportDirection;
                ddlUnit2.SelectedValue = _airportlist[1].AirportUnits;
                txtairportname2.Value = _airportlist[1].Airports;
                txtairportnamecomm2.Value = new Bll.baseinfo.BllAirCode().getcodename(_airportlist[1].Airports);
                txtDis2.Value = _airportlist[1].AirportDistance.ToString();
                txttran2.Value = _airportlist[1].AirportTrans;
                hid2.Value = _airportlist[1].Id.ToString();
            }

            if (_trainlist.Count > 0)
            {
                ddldir3.SelectedValue = _trainlist[0].TrainDirection;
                ddlUnit3.SelectedValue = _trainlist[0].TrainUnits;
                txttrainname1.Value = _trainlist[0].TrainName;
                txttraindis1.Value = _trainlist[0].TrainDistance.ToString();
                txttran3.Value = _trainlist[0].TrainTrans;
                hid3.Value = _trainlist[0].Id.ToString();
            }
            if (_trainlist.Count > 1)
            {
                ddldir4.SelectedValue = _trainlist[1].TrainDirection;
                ddlUnit4.SelectedValue = _trainlist[1].TrainUnits;
                txttrainname2.Value = _trainlist[1].TrainName;
                txttraindis2.Value = _trainlist[1].TrainDistance.ToString();
                txttran4.Value = _trainlist[1].TrainTrans;
                hid4.Value = _trainlist[1].Id.ToString();
            }
            #endregion
        }
    }
}
